package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.SetmealDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;

/**
 * @autahor: csl
 * @date: 2019/7/18
 * @description: 套餐实现类
 * @version:1.0
 */
@Service
public class SetmealServiceImpl  implements SetmealService {
    @Autowired
    private SetmealDao dao;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Setmeal> pages=dao.findPage(queryPageBean.getQueryString());
        return new PageResult(pages.getTotal(),pages.getResult());
    }

    @Override
    public void add(Setmeal setmeal, Integer[] ids) {
        dao.add(setmeal);
        for (Integer id : ids) {
            HashMap<String, Integer> map = new HashMap<>();
            map.put("setmeal_id",setmeal.getId());
            map.put("checkgroup_id",id);
            dao.addSetmealAnd(map);
        }
    }

    @Override
    public List<Setmeal> findAll() {
        return dao.findAll();
    }

    @Override
    public Setmeal findSetmealById(Integer id) {
        return dao.findSetmealById(id);
    }
}
